import React, { Component } from 'react'
import axios from 'axios'

export default class detailList extends Component {
    render() {
        const {detailList,setDetailIsShow} = this.props
        return (
            <div className="detail_list">
                 <div className="header">
                    <span className="iconfont icon-fanhui" onClick={setDetailIsShow} ></span>
                     新闻列表
                </div>
                <div>
                    {
                        detailList.map(item=>{
                            return <div key={item.id}>
                                <p>{item.title}</p>
                                {item.date}
                            </div>
                        })
                    }
                </div>

            </div>
        )
    }
    componentDidMount(){
        //组件初始化让当前新闻全部变为已读状态
        axios.get('/list/read?id='+this.props.id).then(data=>{
            
            if(data.data.code === 1){

                // 更新父组件的列表数据
                this.props.initData(data.data.data)
            }
        })
    }
}
